<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: IOStream</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">IOStream</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../files/vendor/plugins/paperclip/lib/paperclip/iostream_rb.html">
                vendor/plugins/paperclip/lib/paperclip/iostream.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">

    <div id="description">
      <p>
Provides method that can be included on File-type objects (IO, <a
href="StringIO.html">StringIO</a>, <a href="Tempfile.html">Tempfile</a>,
etc) to allow stream copying and <a href="Tempfile.html">Tempfile</a>
conversion.
</p>

    </div>


   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000005">stream_to</a>&nbsp;&nbsp;
      <a href="#M000004">to_tempfile</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">





      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Instance methods</h3>

      <div id="method-M000005" class="method-detail">
        <a name="M000005"></a>

        <div class="method-heading">
          <a href="#M000005" class="method-signature">
          <span class="method-name">stream_to</span><span class="method-args">(path_or_file, in_blocks_of = 8192)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Copies one read-able object from one place to another in blocks, obviating
the need to load the whole thing into memory. Defaults to 8k blocks. If
this module is included in both <a href="StringIO.html">StringIO</a> and <a
href="Tempfile.html">Tempfile</a>, then either can have its data copied
anywhere else without typing worries or memory overhead worries. Returns a
File if a String is passed in as the destination and returns the IO or <a
href="Tempfile.html">Tempfile</a> as passed in if one is sent as the
destination.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000005-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/iostream.rb, line 18</span>
18:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">stream_to</span> <span class="ruby-identifier">path_or_file</span>, <span class="ruby-identifier">in_blocks_of</span> = <span class="ruby-value">8192</span>
19:     <span class="ruby-identifier">dstio</span> = <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">path_or_file</span>
20:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">String</span>   <span class="ruby-keyword kw">then</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path_or_file</span>, <span class="ruby-value str">&quot;wb+&quot;</span>)
21:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">IO</span>       <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">path_or_file</span>
22:             <span class="ruby-keyword kw">when</span> <span class="ruby-constant">Tempfile</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">path_or_file</span>
23:             <span class="ruby-keyword kw">end</span>
24:     <span class="ruby-identifier">buffer</span> = <span class="ruby-value str">&quot;&quot;</span>
25:     <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">rewind</span>
26:     <span class="ruby-keyword kw">while</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">in_blocks_of</span>, <span class="ruby-identifier">buffer</span>) <span class="ruby-keyword kw">do</span>
27:       <span class="ruby-identifier">dstio</span>.<span class="ruby-identifier">write</span>(<span class="ruby-identifier">buffer</span>)
28:     <span class="ruby-keyword kw">end</span>
29:     <span class="ruby-identifier">dstio</span>.<span class="ruby-identifier">rewind</span>    
30:     <span class="ruby-identifier">dstio</span>
31:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000004" class="method-detail">
        <a name="M000004"></a>

        <div class="method-heading">
          <a href="#M000004" class="method-signature">
          <span class="method-name">to_tempfile</span><span class="method-args">()</span>
          </a>
        </div>
      
        <div class="method-description">
          <p>
Returns a <a href="Tempfile.html">Tempfile</a> containing the contents of
the readable object.
</p>
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000004-source">
<pre>
    <span class="ruby-comment cmt"># File vendor/plugins/paperclip/lib/paperclip/iostream.rb, line 6</span>
 6:   <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_tempfile</span>
 7:     <span class="ruby-identifier">name</span> = <span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:original_filename</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">original_filename</span> <span class="ruby-operator">:</span> (<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:path</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">path</span> <span class="ruby-operator">:</span> <span class="ruby-value str">&quot;stream&quot;</span>)
 8:     <span class="ruby-identifier">tempfile</span> = <span class="ruby-constant">Paperclip</span><span class="ruby-operator">::</span><span class="ruby-constant">Tempfile</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">basename</span>(<span class="ruby-identifier">name</span>))
 9:     <span class="ruby-identifier">tempfile</span>.<span class="ruby-identifier">binmode</span>
10:     <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">stream_to</span>(<span class="ruby-identifier">tempfile</span>)
11:   <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>